package com.lzlclass.controller;

import com.lzlclass.http._async.EmailAsync;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.concurrent.Future;

@Controller
public class HelloController {

    @Autowired
    EmailAsync emailAsync;



    @GetMapping("/hello")
    public String hello() throws Exception {
        Future<String> f1 = emailAsync.sendEmail();
        Future<String> f2 = emailAsync.sendEmail2();
        while(true){
            if(f1.isDone()&&f2.isDone()){
//                耗时最长的那个异步结束了
                String s = f1.get();
                String s2 = f2.get();
                System.out.println(s+" | "+s2);
                break;
            }
        }
        return "Hello";
    }

}
